<!DOCTYPE html>
<html>
	<!--
		作者：warden
		时间：2018-06-27
		描述：薪资查询
	-->

	<head>
		<!-- 引入框架文件 -->
		<link rel="stylesheet" href="../../model/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<script type="text/javascript" src="../../model/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../../model/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
		<link rel="stylesheet" href="../../static/css/ehr.css" />
		<link rel="stylesheet" href="../../static/css/employee.css" />
		<script type="text/javascript" src="../../model/models.js"></script>
		<style type="text/css">
			th {
				text-align: center;
			}
		</style>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>

		<div include="../../static/header.htm"></div>
		<div style="height: 100%;float: left;" include="../../static/aside.htm"></div>

		<div class="wire"></div>

		<div class="aside2">
			<div include="../../static/salaryManage.htm"></div>
		</div>

		<div class="section">
			<div style="color: white;font-size: 36px;text-align: center; width: 100%; height: 70px;" class="head"><b>薪资查询</b></div>

			<div style="margin: 5px;" class="panel panel-default">
				<!-- 搜索输入框  -->
				<input type="text" placeholder="搜索方案名称" onkeydown="if(event.keyCode==13) searchSalary();" name="search">
				<a name="search" onclick="return searchSalary();" href="#" style="color: #000000;width: 26px;height: 26px;"><i class="glyphicon glyphicon-search"></i></a>
				<br>

				<table class="table table-bordered" style="margin: 5px 0;">
					<tr>
						<td width="200px">
							排序
							<select>
								<option selected="selected" >按id排序</option>
								<option>按创建时间排序</option>
								<option>按生效日期排序</option>
							</select>
						</td>
					</tr>
				</table>

				<table class="table table-striped" style="text-align: center;" width="100%">
					<thead>
						<tr>
							<th>方案id</th>
							<th>薪资核算方案名称</th>
							<th>生效日期</th>
							<th>失效日期</th>
							<th>所属组织</th>
							<th>备注</th>
							<th>创建人</th>
							<th>创建时间</th>
							<th>更新人</th>
							<th>更新时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="showAllSalaries">
						<tr>
							<td>1</td>
							<td>aaa</td>
							<td>ccc</td>
							<td>ddd</td>
							<td>eee</td>
							<td>fff</td>
							<td>ggg</td>
							<td>aaa</td>
							<td>bbb</td>
							<td>ccc</td>
							<td>
								<a style="color: #000000;" href="#">编辑</a>
								<span><a style="color: #000000;" href="#">删除</a></span>
							</td>
						</tr>
					</tbody>
				</table>

				<!-- 分页开始 -->
				<nav style="position: absolute; bottom: 20px;" aria-label="Page navigation">
					<ul class="pagination">
						<li>
							<a href="#" aria-label="Previous">
								<span aria-hidden="true">&laquo;</span>
							</a>
						</li>
						<li>
							<a href="#">1</a>
						</li>
						<li>
							<a href="#">2</a>
						</li>
						<li>
							<a href="#">3</a>
						</li>
						<li>
							<a href="#">4</a>
						</li>
						<li>
							<a href="#">5</a>
						</li>
						<li>
							<a href="#" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</ul>
				</nav>

				<!-- 分页结束 -->
			</div>

		</div>
		</div>
	</body>

</html>

<script>
	$(function() {
		//显示所有账单数据
		$.ajax({
			type: "post",
			url: "http://localhost:9090/getAllSalaries",
			"data": "",
			"success": function(obj) {
				if(obj.code == 1) {
					var list = obj.data;

					var $showAll = $("#showAllSalaries");
					$showAll.html("");

					for(var i = 0; i < list.length; i++) {
						
						var salary = list[i];
						var $tr = $("<tr id='del"+salary.id+"'></tr>");
						var id;

						for(var index in salary) {
							//要显示的内容
							var content = salary[index];

							if(index == "id") {
								id = content;
							}
							if(index == "dept") {
								content = content["depaName"];
							} else if(index == "creator") {
								content = content["empName"];
							} else if(index == "updator") {
								content = content["empName"];
							}
							var $td = $("<td>" + content + "</td>")
							$tr.append($td);
						}

						$tr.append("<td><a href='updateSalary.html?id=" + salary.id + "' style='color: #000000;'>修改</a>&nbsp;<a onclick='return delSalary(" + salary.id + ")' style='color: #000000;' href=\"#\">删除</a></td>");
						$showAll.append($tr);
					}

				}
			},
			"dataType": "json",
			async: true
		});

	});

	//点击删除
	function delSalary(id) {
		var flag = confirm("你真的要删除吗?");
		if(flag) {

			$.ajax({
				type: "post",
				url: "http://127.0.0.1:9090/delSalary?id=" + id,
				"success": function(obj) {
					if(obj.data) {
						$("#del" + id).html("");
					}
				},
				"dataType": "json",
				async: true
			});
		}

		//console.log(flag);

		return flag;
	}
	
	//点击搜索图标
	function searchSalary()
	{
		//获取搜索字符串
		var searchString = $("input[name='search']").val();
		
		//ajax刷新页面
		$.ajax({
			type: "get",
			url: "http://localhost:9090/findByNameLike?name="+searchString,
			"data": "",
			"success": function(obj) {
				if(obj.code == 1) {
					var list = obj.data;

					var $showAll = $("#showAllSalaries");
					$showAll.html("");

					for(var i = 0; i < list.length; i++) {
						
						var salary = list[i];
						var $tr = $("<tr id='del"+salary.id+"'></tr>");
						var id;

						for(var index in salary) {
							//要显示的内容
							var content = salary[index];

							if(index == "id") {
								id = content;
							}
							if(index == "dept") {
								content = content["depaName"];
							} else if(index == "creator") {
								content = content["empName"];
							} else if(index == "updator") {
								content = content["empName"];
							}
							var $td = $("<td>" + content + "</td>")
							$tr.append($td);
						}

						$tr.append("<td><a href='updateSalary.html?id=" + salary.id + "' style='color: #000000;'>修改</a>&nbsp;<a onclick='return delSalary(" + salary.id + ")' style='color: #000000;' href=\"#\">删除</a></td>");
						$showAll.append($tr);
					}

				}
			},
			"dataType": "json",
			async: true
		});
	}
	
	
	$("select").change(function(){
		if($(this).val()=='按id排序')
		{
			alert('前端干活1');
		}
		else if($(this).val()=='按创建时间排序')
		{
			alert('前端干活2');
		}
		else if($(this).val()=='按生效日期排序')
		{
			alert('前端干活3');
		}
		//console.log($(this).val())
	});
	
	//$("a[name='search']").attr("href","http://127.0.0.1:9090/findByNameLike?name="+$("input[name='search']").val());
</script>